# _*_ coding:utf-8 _*_
# @Time  : 2023.08.13
# @Author: zizlee

from db_utils import BaseDatabaseConnection


class DBUserAuth:
    def __init__(self, db_conn: BaseDatabaseConnection):
        self.db_conn = db_conn

    def section_access(self, user_id: int):  # 用户的模块权限
        self.db_conn.cursor.execute("SELECT id,sec_key,expire_date FROM ruizhi_user_section WHERE user_id=%s AND expire_date>=CURDATE();", [user_id])
        ret = list(self.db_conn.cursor.fetchall())
        return ret

    def section_variety_access(self, sec_key: str, user_id: int):  # 用户模块内品种权限
        self.db_conn.cursor.execute("SELECT id,sec_key,variety_en,expire_date FROM ruizhi_user_section_variety WHERE sec_key=%s AND user_id=%s AND expire_date>=CURDATE();",
                                    [sec_key, user_id])
        ret = list(self.db_conn.cursor.fetchall())
        return ret
